'\" te
.\" Copyright (c) 2006 Sun Microsystems, Inc., All Rights Reserved
.\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License").  You may not use this file except in compliance with the License.
.\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing.  See the License for the specific language governing permissions and limitations under the License.
.\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE.  If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
.TH USB_GET_ALT_IF 9F "Dec 29, 2006"
.SH NAME
usb_get_alt_if, usb_set_alt_if, usb_get_if_number, usb_owns_device \- Get and
set alternate interface values
.SH SYNOPSIS
.nf
#include <sys/usb/usba.h>



\fBint\fR \fBusb_get_alt_if\fR(\fBdev_info_t *\fR\fIdip\fR, \fBuint_t\fR \fIinterface_number\fR,
     \fBuint_t *\fR\fIalternate_number\fR, \fBusb_flags_t\fR \fIflags\fR);
.fi

.LP
.nf
\fBint\fR \fBusb_set_alt_if\fR(\fBdev_info_t *\fR\fIdip\fR, \fBuint_t\fR \fIinterface_number\fR,
     \fBuint_t\fR \fIalternate_number\fR, \fBusb_flags_t\fR \fIflags\fR,
     \fBvoid (*\fR\fIcallback\fR)(usb_pipe_handle_t \fIpipe_handle\fR,
     \fBusb_opaque_t\fR \fIcallback_arg\fR, \fBint\fR \fIrval\fR, \fBusb_cb_flags_t\fR \fIflags\fR),
     \fBusb_opaque_t\fR \fIcallback_arg\fR);
.fi

.LP
.nf
\fB\fR

\fBint\fR \fBusb_get_if_number\fR(\fBdev_info_t *\fR\fIdip\fR);
.fi

.LP
.nf
\fB\fR

\fBboolean_t\fR \fBusb_owns_device\fR(\fBdev_info_t *\fR\fIdip\fR);
.fi

.SH INTERFACE LEVEL
illumos DDI specific (illumos DDI)
.SH PARAMETERS
For \fBusb_get_alt_if()\fR:
.sp
.ne 2
.na
\fB\fIdip\fR\fR
.ad
.RS 20n
Pointer to device's \fBdev_info\fR structure.
.RE

.sp
.ne 2
.na
\fB\fIinterface_number\fR\fR
.ad
.RS 20n
Interface of the desired alternate.
.RE

.sp
.ne 2
.na
\fB\fIalternate_number\fR\fR
.ad
.RS 20n
Address where current alternate setting is returned.
.RE

.sp
.ne 2
.na
\fB\fIflags\fR\fR
.ad
.RS 20n
No flags are recognized. Reserved for future expansion.
.RE

.sp
.LP
For \fBusb_set_alt_if()\fR:
.sp
.ne 2
.na
\fB\fIdip\fR\fR
.ad
.RS 20n
Pointer to device's \fBdev_info\fR structure.
.RE

.sp
.ne 2
.na
\fB\fIinterface_number\fR\fR
.ad
.RS 20n
Interface of the desired alternate.
.RE

.sp
.ne 2
.na
\fB\fIalternate_number\fR\fR
.ad
.RS 20n
Alternate interface number to be set.
.RE

.sp
.ne 2
.na
\fB\fIflags\fR\fR
.ad
.RS 20n
Only USB_FLAGS_SLEEP is recognized. Wait for completion and do not call
callback.
.RE

.sp
.ne 2
.na
\fB\fIcallback\fR\fR
.ad
.RS 20n
Callback handler to notify of asynchronous completion.
.RE

.sp
.ne 2
.na
\fB\fIcallback_arg\fR\fR
.ad
.RS 20n
Second argument passed to callback handler.
.RE

.sp
.LP
For \fBusb_get_if_number()\fR:
.sp
.ne 2
.na
\fB\fIdip\fR\fR
.ad
.RS 7n
Pointer to device's \fBdev_info\fR structure.
.RE

.sp
.LP
For \fBusb_owns_device()\fR:
.sp
.ne 2
.na
\fB\fIdip\fR\fR
.ad
.RS 7n
Pointer to device's \fBdev_info\fR structure.
.RE

.SH DESCRIPTION
USB devices can have multiple configurations, each with many interfaces. Within
interfaces are alternate settings, and within alternate settings are endpoints.
.sp
.LP
Each interface within a configuration may be represented by the kernel as a
device node. Only one set of device nodes (interfaces as determined by the
configuration) can be active at one time.
.sp
.LP
Alternates to an interface represent different ways the kernel sees a device
node. Only one alternate setting within an interface can be active (or
selected) at one time.  The functions presented in this man page get or set
interface or alternate setting information.
.sp
.LP
The \fBusb_get_alt_if()\fR function requests the device to return the current
alternate setting of the given interface. This function ignores the flags
argument and always blocks.
.sp
.LP
The \fBusb_set_alt_if()\fR function requests the device to set the interface
and its alternate setting as specified. Because this call changes the current
device's interface and sets the new interface's mode of operation as seen by
the system, the driver must insure that all pipes other than the default
control pipe are closed and quiescent. To avoid contending with another driver
for a different part of the device, the driver must be bound to: the entire
device, the interface-association which includes the alternative interface, or
to the interface whose number is \fIinterface_number\fR.
.sp
.LP
If \fBUSB_FLAGS_SLEEP\fR is set in flags, \fBusb_set_alt_if()\fR blocks until
completed. Otherwise, \fBusb_set_alt_if()\fR returns immediately and calls the
callback handler when completed.
.sp
.LP
\fIcallback\fR is the asynchronous callback handler and takes the following
arguments:
.sp
.ne 2
.na
\fBusb_pipe_handle_t pipe_handle\fR
.ad
.sp .6
.RS 4n
Handle of the default control pipe used to perform the request.
.RE

.sp
.ne 2
.na
\fBusb_opaque_t callback_arg\fR
.ad
.sp .6
.RS 4n
Callback_arg specified to \fBusb_set_alt_if()\fR.
.RE

.sp
.ne 2
.na
\fBint rval\fR
.ad
.sp .6
.RS 4n
Request status.
.RE

.sp
.ne 2
.na
\fBusb_cb_flags_t callback_flags:\fR
.ad
.sp .6
.RS 4n
Status of the queueing operation. Can be:
.sp
USB_CB_NO_INFO - Callback was uneventful.
.sp
USB_CB_ASYNC_REQ_FAILED   -  Error queueing request.
.sp
USB_CB_NO_RESOURCES   -   Error allocating resources.
.RE

.sp
.LP
The \fBusb_get_if_number()\fR function returns the interface number, or
\fBUSB_COMBINED_NODE\fR or \fBUSB_DEVICE_NODE\fR node indicating that the
driver is bound to the entire device.
.sp
.LP
The \fBusb_owns_device()\fR function returns \fBB_TRUE\fR if the driver of the
dip  argument owns the entire device, or \fBB_FALSE\fR if it owns just a
particular interface.
.SH RETURN VALUES
For \fBusb_get_alt_if()\fR:
.sp
.ne 2
.na
\fBUSB_SUCCESS\fR
.ad
.RS 23n
Interface's alternate setting was successfully obtained.
.RE

.sp
.ne 2
.na
\fBUSB_INVALID_ARGS\fR
.ad
.RS 23n
Pointer to alternate_number and/or dip are NULL.
.RE

.sp
.ne 2
.na
\fBUSB_INVALID_CONTEXT\fR
.ad
.RS 23n
Called from interrupt context.
.RE

.sp
.ne 2
.na
\fBUSB_FAILURE\fR
.ad
.RS 23n
The interface number is invalid.
.sp
An access error occurred.
.RE

.sp
.LP
For \fBusb_set_alt_if()\fR:
.sp
.ne 2
.na
\fBUSB_SUCCESS\fR
.ad
.RS 23n
Alternate interface was successfully set.
.RE

.sp
.ne 2
.na
\fBUSB_INVALID_ARGS\fR
.ad
.RS 23n
dip is NULL. USB_FLAGS_SLEEP is clear and callback is NULL.
.RE

.sp
.ne 2
.na
\fBUSB_INVALID_PERM\fR
.ad
.RS 23n
dip does not own the interface to be set.
.RE

.sp
.ne 2
.na
\fBUSB_INVALID_CONTEXT\fR
.ad
.RS 23n
Called from interrupt context with USB_FLAGS_SLEEP specified.
.RE

.sp
.ne 2
.na
\fBUSB_INVALID_PIPE\fR
.ad
.RS 23n
Pipe handle is NULL, invalid, or refers to a pipe that is closing or closed.
.RE

.sp
.ne 2
.na
\fBUSB_FAILURE\fR
.ad
.RS 23n
The interface number and/or alternate setting are invalid.
.sp
Pipes were open.
.sp
An access error occurred.
.RE

.sp
.LP
For \fBusb_get_if_number()\fR:
.sp
.LP
\fBUSB_COMBINED_NODE\fR if the driver is responsible for the entire active
device configuration. The \fBdip\fR doesn't correspond to an entire physical
device.
.sp
.LP
\fBUSB_DEVICE_NODE\fR if the driver is responsible for the entire device. The
\fIdip\fR corresponds to an entire physical device.
.sp
.LP
interface number: otherwise.
.sp
.LP
For \fBusb_owns_device()\fR:
.sp
.ne 2
.na
\fBB_TRUE\fR
.ad
.RS 11n
Driver of the dip argument owns the entire device.
.RE

.sp
.ne 2
.na
\fBB_FALSE\fR
.ad
.RS 11n
Driver of the dip argument owns only the current interface.
.RE

.SH CONTEXT
The \fBusb_get_if_number()\fR and \fBusb_owns_device()\fR functions may be
called from user or kernel context.
.sp
.LP
The \fBusb_set_alt_if()\fR function may always be called from user or kernel
context. It may be called from interrupt context only if \fBUSB_FLAGS_SLEEP\fR
is not set in flags. If the \fBUSB_CB_ASYNC_REQ_FAILED\fR bit is clear in
\fBusb_cb_flags_t\fR, the callback, if supplied, can block because it is
executing in kernel context. Otherwise the callback cannot block. See
\fBusb_callback_flags\fR(9S) for more information on callbacks.
.sp
.LP
The \fBusb_get_alt_if()\fR function may be called from user or kernel context.
.SH EXAMPLES
.in +2
.nf
/* Change alternate setting of interface 0.  Wait for completion. */
if (usb_set_alt_if(
    dip, 0, new_alternate_setting_num, USB_FLAGS_SLEEP, NULL, 0) !=
    USB_SUCCESS) {
        cmn_err (CE_WARN,
            "%s%d: Error setting alternate setting on pipe",
            ddi_driver_name(dip), ddi_get_instance(dip));
        }
}
.fi
.in -2

.SH ATTRIBUTES
See \fBattributes\fR(7) for descriptions of the following attributes:
.sp

.sp
.TS
box;
c | c
l | l .
ATTRIBUTE TYPE	ATTRIBUTE VALUE
_
Architecture	PCI-based systems
_
Interface stability	Committed
.TE

.SH SEE ALSO
.BR attributes (7),
.BR usb_get_cfg (9F),
.BR usb_get_dev_data (9F),
.BR usb_get_string_descr (9F),
.BR usb_pipe_ctrl_xfer (9F)
